<template>
	<view>
		<view class="bg-white rounded-[20rpx] px-[20rpx] mx-[20rpx] mt-[20rpx]">

			<uv-form labelPosition="left" :model="user" labelWidth="170rpx" :rules="rules" ref="form1">
				<uv-form-item label="支付密码" borderBottom prop="payPassword">
						<view class="py-[10rpx]">
							<up--input v-model="user.payPassword" border="none" password style=" background-color: white;"
								placeholder="请设置支付密码"></up--input>
						</view>
				</uv-form-item>
				<uv-form-item label="确认密码" prop="confirmPassword">
						<view class="py-[10rpx]">
							<up-input v-model="user.confirmPassword" password border="none" style=" background-color: white;"
								placeholder="请确认支付密码">
							</up-input>
						</view>
				</uv-form-item>
			</uv-form>
		</view>
		<view class="py-[20rpx] px-[20rpx] w-full fixed left-0 bottom-[40rpx] box-border">
			<up-button @click="sendData" color="#FE861C" :customStyle="{borderRadius:'20rpx',height:'98rpx'}">
				确认
			</up-button>
		</view>
	</view>
</template>

<script setup>
	import Md5 from "js-md5"
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	import {
		forgotpassword,
		forgetpassword
	} from '@/api/my.js'
	import {
		ref,
		reactive,
		onMounted,
	} from 'vue'
	let telCode = ref()
	onLoad((e) => {
		telCode.value = e.telCode
		console.log("telCode.value", telCode.value, e);
	})
	let user = reactive({
		payPassword: '',
		confirmPassword: '',

	})
	const rules = {
		confirmPassword: {
			type: 'number',
			max: 6,
			required: true,
			message: '请输入6为数字的密码',
			trigger: ['blur', 'change']
		},
		payPassword: {
			type: 'number',
			max: 6,
			required: true,
			message: '请输入6为数字的密码',
			trigger: ['blur', 'change']
		}

	}
	const form1 = ref(null)
	let sendData = () => {
		form1.value.validate().then(res => {
			// console.log("发送短信")
			if (user.payPassword == '' || user.confirmPassword == '') {
				uni.showToast({
					title: '密码不能为空',
					icon: 'none',
					duration: 1000
				});
				return
			}
			// uni.showLoading();
			if (telCode.value) {
				forgetpassword({
					payPassword: Md5(user.payPassword),
					confirmPassword: Md5(user.confirmPassword),
					telCode: telCode.value || ''
				}).then(res => {
					// uni.hideLoading()
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					});
					setTimeout(()=>{
						uni.reLaunch({
							url: '/page_my/myInfo/myInfo'
						})
					},1000)
				
					// handleStartTimer()
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				})
			} else {
				forgotpassword({
					payPassword: Md5(user.payPassword),
					confirmPassword: Md5(user.confirmPassword),
					telCode: telCode.value || ''
				}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					});
					uni.navigateTo({
						url: '/page_my/myInfo/myInfo'
					})
					// handleStartTimer()
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'error',
						duration: 1000
					});
				}).finally(() => {
					uni.hideLoading()
				})
			}

		}).catch(errors => {
			uni.showToast({
				icon: 'none',
				title: '校验失败'
			})
		})


	}
</script>

<style lang="scss">
	.types {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #1A1B1C;
	}

	.typess {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #1A1B1C;
	}
</style>